package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/11/16.
 */

public class GoutongView extends BaseView {
    public GoutongView(Context context) {
        super(context);
        initUI();
    }

    public GoutongView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initUI();
    }

    int textSize = ProportionUtils.getInstance().adapterInt(32);
    int textColor = Color.parseColor("#888888");

    public void initUI() {
        textPaint.setColor(textColor);
        textPaint.setTextSize(textSize);
        textPaint.setTextAlign(Paint.Align.LEFT);
    }

    int width = ProportionUtils.getInstance().adapterInt(647);
    int height = ProportionUtils.getInstance().adapterInt(40);

    String names;
    String[] name;
    String all;
    int index;

    public void setNames(String names) {
        this.names = names;
        name = names.split("、");
        all = "主要沟通人员：" + names;
        requestLayout();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int w = (int) textPaint.measureText(all, 0, all.length());
        if (w > width) {
            setMeasuredDimension(width, height * 2);
            String a = "主要沟通人员：";
            for (int i = 0; i < name.length; i++) {
                a = a + "、" + name[i];
                int w2 = (int) textPaint.measureText(a, 0, a.length());
                if (w2 > width) {
                    index = i;
                    break;
                }
            }

        } else {
            index=0;
            setMeasuredDimension(width, height);
        }
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if(index==0){

        }else {

        }
        //canvas.drawText();
    }
}
